package com.example.managesystem.controller.Student;


import com.example.managesystem.dto.ItemUserUpdateDTO;
import com.example.managesystem.dto.PostItemDTO;
import com.example.managesystem.dto.SubmitMatrialDTO;
import com.example.managesystem.result.Result;
import com.example.managesystem.service.ItemService;
import com.example.managesystem.service.UserService;
import com.example.managesystem.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@CrossOrigin(origins = "*") //origins可以指定请求来源，*代表全部
@Api(tags = "学生端")
@RequestMapping("/stu")
public class StuController {
    @Autowired
    private UserService userService;

    @Autowired
    private ItemService itemService;


    @PostMapping("/postitem")
    @ApiOperation(value = "学生申报项目")
    public Result postItem(@RequestBody PostItemDTO postItemDTO){
        log.info("学生发布项目");
        itemService.saveItem(postItemDTO);
        return Result.success();
    }

    /**
     * 根据用户id查询用户信息
     * @return
     */
    @GetMapping("/userDetail")
    @ApiOperation(value = "查询用户信息")
    public Result selectUserMessage(String userid){
        log.info("根据用户id查询用户信息");
        SelectUserMessageVO selectUserMessageVO=userService.selectUserMessage(userid);
        return Result.success(selectUserMessageVO);
    }
    /**
     * 查询用户个人所有项目
     * @return
     */
    @GetMapping("/myitems")
    @ApiOperation(value = "查询我的项目")
    public Result<ItemsMaintextVO> getMyItems(){
        log.info("查询学生个人所有项目");
        ItemsMaintextVO itemsMaintextVO=userService.getMyItems();
        return Result.success(itemsMaintextVO);
    }



    @GetMapping("/setfailure")
    @ApiOperation(value = "立项失败详情表")
    public Result<SetItemFailureVO> setItemFailure(Integer item_id){
        log.info("立项失败详情表");
        SetItemFailureVO setItemFailureVO=itemService.setItemFailure(item_id);
        return Result.success(setItemFailureVO);
    }

    @GetMapping("/itemdetail")
    @ApiOperation(value = "项目细节详情")
    public Result<PostItemVO> lookItemDetails(Integer item_id){
        log.info("项目细节详情");
        PostItemVO postItemVO=itemService.lookItemDetails(item_id);
        return Result.success(postItemVO);
    }

    @GetMapping("/itemrecord")
    @ApiOperation(value = "项目进展记录")
    public Result<ItemsProgressVO> lookItemProgress(){
        log.info("项目进展记录");
        //查询相关信息
        ItemsProgressVO itemsProgressVO=itemService.lookItemsProgress();
        return  Result.success(itemsProgressVO);
    }

    /**
     * 需要中期审核的项目
     * @return
     */
    @GetMapping("/miditems")
    @ApiOperation(value = "需要中项审核的项目")
    public Result<MidItermsVO> getMidterm(){
        log.info("需要进行中期检查的项目");
        MidItermsVO midItermsVO=itemService.getMidterm();
        return Result.success(midItermsVO);
    }

    /**
     * 提交中期报告
     * @param item_id
     * @return
     */
    @GetMapping("/submitMiditemPaper")
    @ApiOperation(value = "提交中期报告")
    public Result submitMiditemPaper(Integer item_id){
        SubmitMidtermPaperVO submintMidtermPaperVO=itemService.submitMiditemPaper(item_id);
        return Result.success(submintMidtermPaperVO);

    }

    /**
     * 中期审核未通过原因
     * @param item_id
     * @return
     */
    @GetMapping("/miditemFailure")
    @ApiOperation(value = "中期审核未通过原因")
    public Result LookMiditemFailure(Integer item_id){
        SubmitMidtermFailureVO submintMidtermPaperVO=itemService.LookMiditemFailure(item_id);
        return Result.success(submintMidtermPaperVO);
    }

    /**
     * 处于中期项目 之修改成员的基本信息展示
     * @param item_id
     * @return
     */
    @GetMapping("/miditemUpdatePeopleMessage")
    @ApiOperation(value = "处于中期项目 之修改成员的基本信息展示")
    public Result LookMiditemUpdatePeopleMessage(Integer item_id){
        MidItemUpdatePeopleMessageVO midItemUpdatePeopleMessageVO=itemService.LookMiditemUpdatePeopleMessage(item_id);
        return Result.success(midItemUpdatePeopleMessageVO);
    }

    /**
     * 修改项目内成员信息
     * @param itemUserUpdateDTO
     * @return
     */
    @PostMapping("/userUpdate")
    @ApiOperation(value = "修改项目内成员信息")
    public Result midItemUpdatePeople(@RequestBody ItemUserUpdateDTO itemUserUpdateDTO){
        log.info("修改项目成员信息");
        userService.updatePeople(itemUserUpdateDTO);
        return  Result.success();
    }

    /**
     * 获取需要终项审核的项目
     * @return
     */
    @GetMapping("/compeletedItem")
    @ApiOperation(value = "需要结项审核的项目")
    public Result<CompeletedItermsVO> getCompeletedIterms(){
        log.info("需要进行结项审核的项目");
        CompeletedItermsVO compeletedItermsVO=itemService.CompeletedIterms();
        return Result.success(compeletedItermsVO);
    }

    /**
     * 结项审核未通过原因
     * @param item_id
     * @return
     */
    @GetMapping("/compeletedFailure")
    @ApiOperation(value = "结项审核未通过原因")
    public Result LookCompeletedFailure(Integer item_id){
        log.info("结项审核未通过原因");
        SubmitCompeletedItemFailureVO  submintCompeletedFailureVO=itemService.LookCompeletedFailure(item_id);
        return Result.success(submintCompeletedFailureVO);
    }

    /**
     * 提交结项材料
     * @param item_id
     * @return
     */
    @GetMapping("/submitComitemPaper")
    @ApiOperation(value = "提交结项材料")
    public Result submitComitemPaper(Integer item_id){
        log.info("提交结项材料");
        SubmitComitemPaperVO submintCompeletedPaperVO=itemService.submitComitemPaper(item_id);
        return Result.success(submintCompeletedPaperVO);
    }

    /**
     * 准备延期结项申请
     * @param item_id
     * @return
     */
    @GetMapping("/prepareDelayitem")
    @ApiOperation(value = "准备延期结项申请")
    public Result prepareDelayitem(Integer item_id){
        log.info("准备延期结项申请");
        PrepareDelayitemVO prepareDelayitem=itemService.prepareDelayitem(item_id);
        return Result.success(prepareDelayitem);
    }

    /**
     * 提交延期结项申请
     * @param item_id
     * @return
     */
    @PostMapping("/submitDelayitem")
    @ApiOperation(value = "提交延期结项申请")
    public Result submitDelayitem(Integer item_id,String reason){
        log.info("提交延期结项申请");
        itemService.submitDelayitem(item_id,reason);
        return Result.success();
    }

    /**
     * 延期项目详情
     * @param item_id
     * @return
     */
    @GetMapping("/delayitemDetail")
    @ApiOperation(value = "延期项目详情")
    public Result LookDelayitemDetail(Integer item_id){
        log.info("延期项目详情");
        DelayItemDetailVO delayItemDetailVO=itemService.LookDelayitemDetail(item_id);
        return Result.success(delayItemDetailVO);
    }

    /**
     * 结项审核准备材料提交
     * @param item_id
     * @return
     */
    @GetMapping("/prepareSubmitMaterial")
    @ApiOperation(value = "结项审核准备材料提交")
    public Result prepareSubmitMaterial(Integer item_id){
        log.info("结项审核材料提交准备");
        PrepareSubmitMaterialVO prepareSubmitMaterial=itemService.prepareSubmitMaterial(item_id);
        return Result.success(prepareSubmitMaterial);
    }

    /**
     * 提交材料
     * @param
     * @return
     */
    @PostMapping ("/submitMaterial")
    @ApiOperation(value = "提交材料")
    public Result SubmitMaterial(@RequestBody SubmitMatrialDTO submitMatrialDTO){
        log.info("提交材料");
        itemService.submitMaterial(submitMatrialDTO);
        return Result.success();
    }




}
